<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
    <#include "/common/base_include.ftl"/>
</head>
<body>
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-3">
            <div class="ibox ibox-body">
                <div class="ibox-title">
                    <h5>部门列表</h5>
                </div>
                <div class="ibox-content">
                    <div id="jstree"></div>
                </div>
            </div>
        </div>
        <div class="col-sm-8">
            <div class="ibox">
                <div class="ibox-body">
                    <div class="fixed-table-toolbar">
                        <div class="columns pull-right">
                            <button class="btn btn-success" onclick="reLoad()">查询</button>
                        </div>
                        <div class="columns pull-right col-md-2 nopadding">
                            <input id="searchName" type="text" class="form-control" placeholder="姓名">
                        </div>
                    </div>
                    <div id="toolbar" class="btn-group">
                        <@shiro.hasPermission name="sys:user:add">
                            <button type="button"
                                    class="btn  btn-primary btn-group-xs add_btn" data-url="/sys/user/modify"
                                    id="add_button">
                                <i class="fa fa-plus hidden" aria-hidden="true" data-url="/sys/user/modify"></i>添加
                            </button>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name="sys:user:edit">
                            <button type="button" class="btn  btn-info btn-group btn-group-xs edit_btn"
                                    data-url="/sys/user/modify">
                                <i class="fa fa-plus hidden" aria-hidden="true"></i>修改
                            </button>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name="sys:user:remove">
                            <button type="button"
                                    class="btn  btn-warning   btn-group btn-group-xs remove_btn"
                                    data-url="/sys/user/remove">
                                <i class="fa fa-trash hidden" aria-hidden="true"></i>删除
                            </button>
                        </@shiro.hasPermission>
                    </div>
                    <table id="exampleTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        var deptId = '';
        getTreeData('jstree', '/system/sysDept/tree', true);
        $('#jstree').on("changed.jstree", function (e, data) {
            if (data.selected != -1) {
                deptId = data.selected[0];
            }
            $("#add_button").attr("data-url", "/sys/user/modify?deptId=" + deptId);
            reLoad();
        });
        //load table
        var columns = [
            {radio: true},
            {
                field: 'userId', // 列字段名
                title: '序号' // 列标题
            },
            {
                field: 'name',
                title: '姓名'
            },
            {
                field: 'username',
                title: '用户名'
            },
            {
                field: 'email',
                title: '邮箱'
            },
            {
                field: 'status',
                title: '状态',
                align: 'center',
                formatter: function (value, row, index) {
                    if (value == '0') {
                        return '<span class=\'label label-danger\'>禁用</span>';
                    } else if (value == '1') {
                        return '<span class=\'label label-primary\'>正常</span>';
                    }
                }
            }
            <@shiro.hasPermission name="sys:user:resetPwd">
            , {
                title: '重置密码',
                field: 'id',
                align: 'center',
                formatter: function (value, row, index) {
                    var f = '<@shiro.hasPermission name="sys:user:resetPwd">' +
                        '<a class="btn btn-success btn-sm " href="#" title="重置密码"  mce_href="#" onclick="resetPwd(\''
                        + row.userId
                        + '\')"><i class="fa fa-key"></i></a>' +
                        ' </@shiro.hasPermission>';
                    var e = '<@shiro.hasPermission name="sys:user:finger">' +
                        '<a class="btn btn-info btn-sm " href="#" title="指纹"  mce_href="#" onclick="modifyFinger(\''
                        + row.userId
                        + '\')"><i class="fa fa-thumbs-o-up"></i></a>' +
                        ' </@shiro.hasPermission>';
                    return e + f;
                }
            }
            </@shiro.hasPermission>
        ];
        var param = function (params) {
            return {
                limit: params.limit,
                offset: params.offset,
                name: $('#searchName').val(),
                deptId: deptId
            }
        };
        loadTable("/sys/user/list", columns, param, 'userId');
    });

    function resetPwd(userId) {
        $.ajax({
            cache: true,
            type: "POST",
            url: "/sys/user/adminResetPwd",
            data: {"userDO.userId": userId},// 你的formid
            async: false,
            error: function (request) {
                parent.layer.msg("系统错误，联系管理员");
            },
            success: function (data) {
                parent.layer.msg(data.msg);
            }
        });
    }

    function modifyFinger(userId) {
        var url = "/user/finger?userId=" + userId;
        var open_param = {
            type: 2,
            title: "指纹管理",
            btn: ['关闭'],
            content: url,
            end: function (index, layero) {
                layer.close(index);
            }
        };
        layer_open(open_param);
    }
</script>
</html>